package control

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.shiyan2.R
import kotlinx.android.synthetic.main.phone_layout.view.*
import model.goods

class goodsAdapter(activity: Activity, val resourceId: Int, data: List<goods>) :
    ArrayAdapter<goods>(activity,resourceId,data){

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view=LayoutInflater.from(context).inflate(resourceId,parent,false)
        val img:ImageView=view.goodsimg
        val name:TextView=view.name
        val price:TextView=view.price
        val sort:TextView=view.sort
        val comment:TextView=view.comment
        val store:TextView=view.store
        val goods=getItem(position)
        if(goods!=null){
            img.setImageResource(goods.img)
            name.text=goods.name
            price.text="￥"+goods.price.toString()
            sort.text=goods.sort
            comment.text=goods.comment
            store.text=goods.store
            price.setTextColor(android.graphics.Color.RED)
            sort.setBackgroundColor(android.graphics.Color.RED)
        }
        return view
    }
}